package com.yanqu.road.dao.impl.activity.twins;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.twins.config.*;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class TwinsConfigDaoImpl extends TempDao {

    public static String get1Sql = "select * from t_s_activity_twins_kungfu where activityId= ?";
    public Map<Integer, Map<Integer, TwinsKungFuConfig>> getKungFuConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, Map<Integer, TwinsKungFuConfig>> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get1Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                TwinsKungFuConfig data = new TwinsKungFuConfig();
                data.setId(rs.getInt("id"));
                data.setOriginType(rs.getInt("originType"));
                data.setKungfuType(rs.getInt("kungfuType"));
                data.setQuality(rs.getInt("quality"));
                data.setLevel(rs.getInt("level"));
                data.setIcon(rs.getString("icon"));
                data.setName(rs.getString("name"));
                data.setDesc(rs.getString("desc"));
                data.setCost(rs.getInt("cost"));
                data.setAnger(rs.getString("anger"));
                data.setSkillEffect(rs.getString("skillEffect"));
                data.setHaloType(rs.getInt("haloType"));
                data.setRange(rs.getInt("range"));
                data.setBlowHarmWeights(rs.getString("blowHarmWeights"));
                data.setRepelRange(rs.getString("repelRange"));
                data.setKungfuDesc(rs.getString("kungfuDesc"));
                data.setVibrationAmplitude(rs.getString("vibrationAmplitude"));
                data.setFightDesc(rs.getString("fightDesc"));
                if(!result.containsKey(data.getId())){
                    result.put(data.getId(), new ConcurrentHashMap<>());
                }
                result.get(data.getId()).put(data.getLevel(),data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    public static String get2Sql = "select * from t_s_activity_twins_kungfu_comb where activityId= ?";
    public Map<Integer, TwinsKungFuCombConfig> getKungFuCombConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, TwinsKungFuCombConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get2Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                TwinsKungFuCombConfig data = new TwinsKungFuCombConfig();
                data.setId(rs.getInt("id"));
                data.setLevel(rs.getInt("level"));
                data.setName(rs.getString("name"));
                data.setDesc(rs.getString("desc"));
                data.setNeedOriginLevel(rs.getString("needOriginLevel"));
                data.setNeedKungfuLevel(rs.getString("needKungfuLevel"));
                data.setSkillEffect(rs.getString("skillEffect"));
                data.setRewards(rs.getString("rewards"));
                data.setEffectDesc(rs.getString("effectDesc"));
                data.setType(rs.getInt("type"));
                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    public static String get3Sql = "select * from t_s_activity_twins_mission where activityId= ?";
    public Map<Integer, TwinsMissionConfig> getMissionConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, TwinsMissionConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get3Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                TwinsMissionConfig data = new TwinsMissionConfig();
                data.setId(rs.getInt("id"));
                data.setType(rs.getInt("type"));
                data.setName(rs.getString("name"));
                data.setRecommendPower(rs.getString("recommendPower"));
                data.setMonsterId(rs.getString("monsterId"));
                data.setBossId(rs.getString("bossId"));
                data.setMonsterPower(rs.getString("monsterPower"));
                data.setBossPower(rs.getString("bossPower"));
                data.setRewards(rs.getString("rewards"));
                data.setSweepRewards(rs.getString("sweepRewards"));
                data.setSweepRandomRewards(rs.getString("sweepRandomRewards"));
                data.setFailRewards(rs.getString("failRewards"));
                data.setIsBoss(rs.getInt("isBoss"));
                data.setMap(rs.getInt("map"));
                data.setEnergyCost(rs.getInt("energyCost"));
                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    public static String get4Sql = "select * from t_s_activity_twins_npc where activityId= ?";
    public Map<Integer, TwinsNpcConfig> getNpcConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, TwinsNpcConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get4Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                TwinsNpcConfig data = new TwinsNpcConfig();
                data.setId(rs.getInt("id"));
                data.setOrdinaryKungfu(rs.getString("ordinaryKungfu"));
                data.setCoreKungfu(rs.getString("coreKungfu"));
                data.setAnger(rs.getInt("anger"));
                data.setIcon(rs.getInt("icon"));
                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }


    public static String get5Sql = "select * from t_s_activity_twins_lottery where activityId= ?";
    public Map<Integer, TwinsLotteryConfig> getLotteryConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, TwinsLotteryConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get5Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                TwinsLotteryConfig data = new TwinsLotteryConfig();
                data.setId(rs.getInt("id"));
                data.setName(rs.getString("name"));
                data.setWeights(rs.getInt("weights"));
                data.setRewards(rs.getInt("rewards"));
                data.setIsHide(rs.getInt("isHide"));
                data.setSort(rs.getInt("sort"));
                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    public static String get6Sql = "select * from t_s_activity_twins_pvp where activityId= ?";
    public Map<Integer, TwinsPvpConfig> getPvpConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, TwinsPvpConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get6Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                TwinsPvpConfig data = new TwinsPvpConfig();
                data.setId(rs.getInt("id"));
                data.setRecommendPower(rs.getString("recommendPower"));
                data.setIcon(rs.getInt("icon"));
                data.setName(rs.getString("name"));
                data.setDesc(rs.getString("desc"));
                data.setBossPower(rs.getString("bossPower"));
                data.setRefreshTime(rs.getInt("refreshTime"));
                data.setDarePoint(rs.getString("darePoint"));
                data.setRewards(rs.getString("rewards"));
                data.setScoreRewards(rs.getString("scoreRewards"));
                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    public static String get7Sql = "select * from t_s_activity_twins_map where activityId= ?";
    public Map<Integer, TwinsMapConfig> getMapConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, TwinsMapConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get7Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                TwinsMapConfig data = new TwinsMapConfig();
                data.setId(rs.getInt("id"));
                data.setDesc(rs.getString("desc"));
                data.setNpcId(rs.getInt("npcId"));
                data.setCoreKungfu(rs.getString("coreKungfu"));
                data.setName(rs.getString("name"));
                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }
}
